﻿using System;
using System.Collections;
using System.Collections.Generic;
using CalcSharp.Core.Containers;
using CalcSharp.Core.Plugin;
using plug_mtrximage.HelperClasses;

namespace plug_mtrximage
{
    class PlugMtrxMerge: ICMDPlugin
    {
        private IPluginHost host;

        public Tresult Run(ArrayList parameters)
        {
            Tresult res = new Tresult();
            AMatrix in1, in2;
            string mergeefect = Convert.ToString(parameters[2]).ToUpper();
            in1 = host.Mtrx_mem[Convert.ToString(parameters[0])];
            in2 = host.Mtrx_mem[Convert.ToString(parameters[1])];

            switch (mergeefect)
            {
                case "ADDITION":
                    Efects.MergeImages(in1, in2, BlendMode.Addition, host.Mtrx_mem.StorageType);
                    break;
                case "BURN":
                    Efects.MergeImages(in1, in2, BlendMode.Burn, host.Mtrx_mem.StorageType);
                    break;
                case "DARKENONLY":
                    Efects.MergeImages(in1, in2, BlendMode.DarkenOnly, host.Mtrx_mem.StorageType);
                    break;
                case "DIFFERENCE":
                    Efects.MergeImages(in1, in2, BlendMode.Difference, host.Mtrx_mem.StorageType);
                    break;
                case "DIVIDE":
                    Efects.MergeImages(in1, in2, BlendMode.Divide, host.Mtrx_mem.StorageType);
                    break;
                case "DODGE":
                    Efects.MergeImages(in1, in2, BlendMode.Dodge, host.Mtrx_mem.StorageType);
                    break;
                case "GRAINEXTRACT":
                    Efects.MergeImages(in1, in2, BlendMode.GrainExtract, host.Mtrx_mem.StorageType);
                    break;
                case "GRAINMERGE":
                    Efects.MergeImages(in1, in2, BlendMode.GrainMerge, host.Mtrx_mem.StorageType);
                    break;
                case "HARDLIGHT":
                    Efects.MergeImages(in1, in2, BlendMode.HardLight, host.Mtrx_mem.StorageType);
                    break;
                case "LIGHTENONLY":
                    Efects.MergeImages(in1, in2, BlendMode.LightenOnly, host.Mtrx_mem.StorageType);
                    break;
                case "MULTIPLY":
                    Efects.MergeImages(in1, in2, BlendMode.Multiply, host.Mtrx_mem.StorageType);
                    break;
                case "OVERLAY":
                    Efects.MergeImages(in1, in2, BlendMode.Overlay, host.Mtrx_mem.StorageType);
                    break;
                case "SCREEN":
                    Efects.MergeImages(in1, in2, BlendMode.Screen, host.Mtrx_mem.StorageType);
                    break;
                case "SOFTLIGHT":
                    Efects.MergeImages(in1, in2, BlendMode.SoftLight, host.Mtrx_mem.StorageType);
                    break;
                case "SUBTRACT":
                    Efects.MergeImages(in1, in2, BlendMode.Subtract, host.Mtrx_mem.StorageType);
                    break;
            }
            return res;
        }

        public string Name
        {
            get { return "MTRX_MERGE"; }
        }

        public Dictionary<string, string> autocomplete
        {
            get
            {
                Dictionary<string, string> elements = new Dictionary<string, string>();
                elements.Add("Color merge efects", "ADDITION;BURN;DARKENONLY;DIFFERENCE;DIVIDE;DODGE;GRAINEXTRACT;GRAINMERGE;HARDLIGHT;LIGHTENONLY;MULTIPLY;OVERLAY;SCREEN;SOFTLIGHT;SUBTRACT");
                return elements;
            }
        }

        public string Help
        {
            get { throw new NotImplementedException(); }
        }

        public IPluginHost Host
        {
            get { return host; }
            set
            {
                host = value;
                host.Register(this);
            }
        }
    }
}
